package com.uplooking.spider;

import com.uplooking.spider.task.PageListTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 爬虫的入口
 */
@SpringBootApplication
public class Spider implements CommandLineRunner {
    @Autowired
    private PageListTask pageListTask;


    public static void main(String[] args) {
        SpringApplication.run(Spider.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("爬虫开始爬取数据........");
        //创建一个线程池(2个线程)   一个线程用来下载页面列表   另外一个线程用来下载具体的页面内容
        ExecutorService threadPool = Executors.newFixedThreadPool(2);

        //下载页面列表并且解析页面列表
        threadPool.execute(pageListTask);
    }
}
